package network.protocol;

import java.io.Serializable;

/**
 * @author Erik
 * The package that contains all about an attack
 */

@SuppressWarnings("serial")
public class AttackPackage implements Serializable {
	private int curBuilding, targetBuilding;
	//amount is a quota from the client and a number from server
	private int amount;
	
	public AttackPackage(int curBuilding, int targetBuilding, int amount){
		this.curBuilding = curBuilding;
		this.targetBuilding = targetBuilding;
		this.amount = amount;
	}
	
	/**
	 * convert a correct formated string to a AttackPackage
	 * format: curBuilding(int) + \n + targetBuilding(int) + \n + amount(int) + \n
	 * @param data
	 */
	public AttackPackage(String data){
		int start = 0, end = 0;
		
		end = data.indexOf('\n', start);	
		curBuilding = Integer.parseInt(data.substring(start, end));
		start = end + 1;
		
		end = data.indexOf('\n', start);
		targetBuilding = Integer.parseInt(data.substring(start, end));
		start = end + 1;

		end = data.indexOf('\n', start);
		amount = Integer.parseInt(data.substring(start, end));
		
	}
	
	/**
	 * convert the AttackPackage to a correct formated string
	 * @return
	 */
	public String toPackage(){
		StringBuilder res = new StringBuilder();
		res.append(curBuilding);
		res.append('\n');
		
		res.append(targetBuilding);
		res.append('\n');
		
		res.append(amount);
		res.append('\n');
		return res.toString();
	} 


	public int getAmount(){
		return amount;
	}
	
	public void setAmount(int amount){
		this.amount = amount;
	}
	
	public int getCurBuilding(){
		return curBuilding;
	}
	
	public int getTargetBuilding(){
		return targetBuilding;
	}
}

